package com.zy.mc_module.ui.micang;

import android.content.Context;

import com.zy.mc_module.mvp.base.BasePresenter;
import com.zy.mc_module.mvp.bean.MasterLevelBean;
import com.zy.mc_module.mvp.bean.PageBean;
import com.zy.mc_module.mvp.bean.RiceDetailBean;
import com.zy.mc_module.mvp.bean.RiceStoreHouseBean;
import com.zy.mc_module.mvp.bean.UserActiveBean;
import com.zy.mc_module.mvp.bean.UserBean;
import com.zy.mc_module.mvp.bean.UserExperienceBean;
import com.zy.mc_module.mvp.bean.UserTaskCount;
import com.zy.mc_module.utils.retrofit.RxObserver;
import com.zy.mc_module.utils.retrofit.RxTransform;
import com.zy.mc_module.utils.retrofit.error.ThdException;

import java.util.List;

public class RicePresenter extends BasePresenter<RiceContract.View> {
    private RiceModel miCangModel;
    public static final int USER_MEMBER_INFO = 1001;
    public static final int USER_TASK_COUNT = 1002;
    public static final int RICE_STORE_HOUSE = 1003;
    public static final int USER_RICE_STORE = 1004;
    public static final int USER_ACCOUNT_RECORD = 1005;
    public static final int USER_ACTIVE_RECORD = 1006;
    public static final int USER_REWARD_EXPERIENCE = 1007;
    public static final int MASTER_LIST = 1008;

    public RicePresenter() {
        miCangModel = new RiceModel();
    }

    public void getUserInfo(Context context){
        miCangModel.getUserBaseInfo().compose(RxTransform.schedule())
                .subscribe(new RxObserver<UserBean.UserMemberInfo>(this,context) {
                    @Override
                    protected void onBaseNext(UserBean.UserMemberInfo userMemberInfo) {
                        getView().onSuccess(userMemberInfo,USER_MEMBER_INFO);
                    }

                    @Override
                    protected void onBaseError(ThdException e) {
                        getView().onError(e,USER_MEMBER_INFO);
                    }
                });
    }

    public void userTaskCount(Context context)
    {
        miCangModel.userTaskCount().compose(RxTransform.schedule())
                .subscribe(new RxObserver<UserTaskCount>(this,context) {
                    @Override
                    protected void onBaseNext(UserTaskCount userTaskCount) {
                        getView().onSuccess(userTaskCount,USER_TASK_COUNT);
                    }

                    @Override
                    protected void onBaseError(ThdException e) {
                        getView().onError(e,USER_TASK_COUNT);
                    }
                });
    }

    public void riceStoreHouseFindAll(Context context){
        miCangModel.riceStoreHouseFindAll().compose(RxTransform.schedule())
                .subscribe(new RxObserver<List<RiceStoreHouseBean>>(this,context) {
                    @Override
                    protected void onBaseNext(List<RiceStoreHouseBean> riceStoreHouseBeans) {
                        getView().onSuccess(riceStoreHouseBeans,RICE_STORE_HOUSE);
                    }

                    @Override
                    protected void onBaseError(ThdException e) {
                        getView().onError(e,RICE_STORE_HOUSE);
                    }
                });
    }

    public void getUserRiceStoreList(Context context,int state,int page)
    {
        miCangModel.getUserRiceStoreList(state, page).compose(RxTransform.schedule())
                .subscribe(new RxObserver<PageBean<RiceStoreHouseBean>>(this,context) {
                    @Override
                    protected void onBaseNext(PageBean<RiceStoreHouseBean> riceStoreHouseBeanPageBean) {
                        getView().onSuccess(riceStoreHouseBeanPageBean,USER_RICE_STORE);
                    }

                    @Override
                    protected void onBaseError(ThdException e) {
                        getView().onError(e,USER_RICE_STORE);
                    }
                });
    }

    public void userAccountRecord(Context context,int page)
    {
        miCangModel.userAccountRecord(page).compose(RxTransform.schedule())
                .subscribe(new RxObserver<PageBean<RiceDetailBean>>(this,context) {
                    @Override
                    protected void onBaseNext(PageBean<RiceDetailBean> riceDetailBeanPageBean) {
                        getView().onSuccess(riceDetailBeanPageBean,USER_ACCOUNT_RECORD);
                    }

                    @Override
                    protected void onBaseError(ThdException e) {
                        getView().onError(e,USER_ACCOUNT_RECORD);
                    }
                });
    }

    public void userActiveRecordPage(Context context,int page){
        miCangModel.userActiveRecordPage(page).compose(RxTransform.schedule())
                .subscribe(new RxObserver<PageBean<UserActiveBean>>(this,context) {
                    @Override
                    protected void onBaseNext(PageBean<UserActiveBean> userActiveBeanPageBean) {
                        getView().onSuccess(userActiveBeanPageBean,USER_ACTIVE_RECORD);
                    }

                    @Override
                    protected void onBaseError(ThdException e) {
                        getView().onError(e,USER_ACTIVE_RECORD);
                    }
                });
    }

    public void rewardExperienceUser(Context context,int page){
        miCangModel.rewardExperienceUser(page).compose(RxTransform.schedule())
                .subscribe(new RxObserver<PageBean<UserExperienceBean>>(this,context) {
                    @Override
                    protected void onBaseNext(PageBean<UserExperienceBean> userActiveBeanPageBean) {
                        getView().onSuccess(userActiveBeanPageBean,USER_REWARD_EXPERIENCE);
                    }

                    @Override
                    protected void onBaseError(ThdException e) {
                        getView().onError(e,USER_REWARD_EXPERIENCE);
                    }
                });
    }

    public void masterList(Context context){
        miCangModel.masterList().compose(RxTransform.schedule())
                .subscribe(new RxObserver<List<MasterLevelBean>>(this,context) {
                    @Override
                    protected void onBaseNext(List<MasterLevelBean> masterLevelBeanList) {
                        getView().onSuccess(masterLevelBeanList,MASTER_LIST);
                    }

                    @Override
                    protected void onBaseError(ThdException e) {
                        getView().onError(e,MASTER_LIST);
                    }
                });
    }
}
